package com.cskaoyan.demo1.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import java.io.IOException;
import java.util.Properties;

/**
 * @Description：
 * @Author：BLUEBLANK
 * @Date：2024/4/7 13:40
 */

@WebServlet(value = "/init",loadOnStartup = 1) // 设置loadOnStartup为正数 立即加载
public class ParameterInitServlet extends HttpServlet {
    @Override
    public void init() throws ServletException {
        Properties properties = new Properties();
        try {
            properties.load(AdminStorageServlet.class.getClassLoader().getResourceAsStream("parameter.properties"));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        String storagePath = properties.getProperty("storagePath");
        String urlPrefix = properties.getProperty("urlPrefix");

        // servletContext 进行设置
        getServletContext().setAttribute("storagePath",storagePath);
        getServletContext().setAttribute("urlPrefix",urlPrefix);

    }
}
